import Immutable from 'seamless-immutable'
import { createSlice } from '@reduxjs/toolkit'
import createRequestTypes from '@UTILS/reduxHelper'
import { DeviceState } from '@CONSTANTS/BleConstants'

const HOME = createRequestTypes('HOME')

const INITIAL_STATE = Immutable({
  deviceData: {
    state: '' as DeviceState,
    treatmentElapsedTimeInSeconds: 0, // 治疗进行了多少秒
    treatmentTimeLeftInSeconds: 0, // 治疗剩余时间总秒数
    treatmentActualIntensityInPercentage: 0,
    treatmentConfiguredIntensityInPercentage: 12, // 强度
    pauseRemainingTimeInSeconds: 0, // 暂停剩余时间
    numberOfTreatments: 0,
    numberOfPauseTreatmentsLeft: 3, // 剩余暂停次数
    flags: {
      isLastTreatmentStatisticsAvailable: false,
      isReportAvailable: false,
      isInNoLoadState: false,
    },
  },
})

const homeSlice = createSlice({
  name: 'home',
  initialState: INITIAL_STATE,
  reducers: {
    setDeviceData: (state, action) => ({
      ...state,
      deviceData: { ...action.payload },
    }),
  },
})

const { actions } = homeSlice
export { actions, HOME }

export default homeSlice.reducer
